$(document).ready(function(){
    $.ajax({
        url: '/api/boss-info/',
        type: 'GET',
        dataType: 'json',
        success: function (data){
            let categories = ['0-10k', '10-20k', '20-30k', '30-40k', '40k以上'];
            let series = [];
            let keys = Object.keys(data);
            keys.forEach(key => {
                series.push({
                    name: key,
                    type: 'bar',
                    data: data[key].map(value => parseFloat(value)),
                    markPoint: {
                        data: [
                            {type: 'max', name: 'Max'},
                            {type: 'min', name: 'Min'}
                        ]
                    }
                });
            });

            // 设置options
            let myChart = echarts.init($('#salary-chart')[0]);
            let option= {
                title: {
                    text: '薪资情况分析',
                    subtext: 'IT行业'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: keys
                },
                toolbox: {
                    show: true,
                    feature: {
                        dataView: { show: true, readOnly: false },
                        magicType: { show: true, type: ['line', 'bar'] },
                        restore: { show: true },
                        saveAsImage: { show: true }
                    }
                },
                calculable: true,
                xAxis: [
                    {
                        type: 'category',
                        data: categories
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: series
            };
            // 渲染图表
            option && myChart.setOption(option);
        },
        error: function (error){
            console.log(error);
        }
    });

    // 测试接口 /api/vue3/items/
    $.ajax({
        url: '/api/vue3/items/',
        type: 'get',
        dataType: 'json',
        success: function (data){
            console.log('请求成功');
            console.log(data);
        },
    })
})

